<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link href="/ajax/libs/jquery-layout/jquery.layout-latest.css" th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
<link href="/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css" th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>

<body class="gray-bg">
	<div class="ui-layout-west">
		<div class="main-content">
			<div class="box box-main">
				<div class="box-header">
					<div class="box-title">
						<i class="fa icon-grid"></i> 班级架构
					</div>
					<div class="box-tools pull-right">
						<button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
						<button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
						<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新机构"><i class="fa fa-refresh"></i></button>
					</div>
				</div>
				<div class="ui-layout-content">
					<div id="tree" class="ztree"></div>
				</div>
			</div>
		</div>
	</div>
    <div class="container-div ui-layout-center" >
    	<div class="row">
    		<div class="col-sm-12 select-info">
				<form id="operlog-form">
					<input type="hidden" id="classNumber" name="classNumber">
					<input type="hidden" id="gradeNumber" name="classes.gradeNumber">
					<div class="select-list gd">
						<ul>
							<li>
								姓名：<input type="text" name="name" style="width: 100px;"/>
							</li>
							<li>
								学生状态：<select name="status" style="width: 100px;" th:with="type=${@dictService.selectDictData('student_status')}">
									<option value="">所有</option>
									<option th:each="e : ${type}" th:text="${e['dictLabel']}" th:value="${e['dictValue']}"></option>
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search($('form').attr('id'))"><i class="fa fa-search"></i>&nbsp;搜索</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
	        <div class="btn-group hidden-xs" id="toolbar" role="group">
		        <button class="btn btn-outline btn-success btn-rounded" onclick="$.operate.add()" shiro:hasPermission="module:student:add">
		            <i class="fa fa-plus"></i> 新增
		        </button>
		        <button class="btn btn-outline btn-danger btn-rounded" onclick="$.operate.batRemove()" shiro:hasPermission="module:student:remove">
		            <i class="fa fa-trash-o"></i> 删除
		        </button>
	        </div>
	        <div class="col-sm-12 select-info order-table">
		        <table id="bootstrap-table" data-mobile-responsive="true">
		        </table>
	        </div>
	    </div>
    </div>
    <div th:include="include :: footer"></div>
    <script th:src="@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"></script>
	<script th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
	<script th:inline="javascript">
        var editFlag = [[${@permissionService.hasPermi('module:student:edit')}]];
        var removeFlag = [[${@permissionService.hasPermi('module:student:remove')}]];
        var prefix = ctx + "module/student"

        $(document).ready(function(){
			$('body').layout({ west__size: 185 });
			queryUserList();
			queryClassesTreeDaTa();
		});
        
        function queryUserList() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "学生",
                search: false,
		        showExport: false,
                columns: [{
		            checkbox: true
		        },
		        {
		            title: '序号',
		            field: 'studentNumber',
		            align: 'center',
		            formatter: function (value, row, index) {
		                var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;     //通过table的#id 得到每页多少条
		                var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber; //通过table的#id 得到当前第几页
		                return pageSize * (pageNumber - 1) + index + 1;    // 返回每条的序号： 每页条数 *（当前页 - 1 ）+ 序号
		            }
		        },
				{
					field : 'studentNumber', 
					align: 'center',
					title : '学号' 
				},
				{
					field : 'name',
					align: 'center',
					title : '姓名' 
				},
				{
					field : 'sex',
					align: 'center',
					title : '性别',
				 	formatter: function (value, row, index) {
				 		if(value == "0"){
				 			return "男";
				 		}else if(value == "1"){
				 			return "女";
				 		}else{
				 			return "未知";
				 		}
		            }
				},
				{
					field : 'classes.name',
					align: 'center',
					title : '所在班级' 
				},
				{
					field : 'status', 
					align: 'center',
					title : '状态',
					formatter: function (value, row, index) {
				 		if(value == "1"){
				 			return "在籍";
				 		}else{
				 			return value;
				 		}
		            }
				},
				{
					field : '', 
					align: 'center',
					title : '家长1',
					formatter: function(value, row, index) {
						if(row.parents.length>0){
						return row.parents[0].name+"("+getAppellation(row.parents[0].appellation)+")";
						}
		            }
				},
				{
					field : '', 
					align: 'center',
					title : '联系电话' ,
					formatter: function(value, row, index) {
						if(row.parents.length>0){
							return row.parents[0].telephone;
						}
		            }
				},
				{
					field : 'openId', 
					align: 'center',
					title : '微信绑定',
					formatter: function(value, row, index) {
						if(row.parents.length>0){
						if (row.parents[0].openId == '' || row.parents[0].openId == null) {
		                    return '<span class="badge badge-danger">否</span>';
		                } else {
		                    return '<span class="badge badge-primary">是</span>';
		                }
						}
		            }
				},
				{
					field : '', 
					align: 'center',
					title : '家长2',
					formatter: function(value, row, index) {
						if(row.parents.length>1){
							return row.parents[1].name+"("+getAppellation(row.parents[1].appellation)+")";
						}
		            }
				},
				{
					field : '', 
					align: 'center',
					title : '联系电话' ,
					formatter: function(value, row, index) {
						if(row.parents.length>1){
							return row.parents[1].telephone;
						}
		            }
				},
				{
					field : 'openId',
					align: 'center',
					title : '微信绑定',
					formatter: function(value, row, index) {
						if(row.parents.length>1){
							if (row.parents[1].openId == '' || row.parents[1].openId == null) {
			                    return '<span class="badge badge-danger">否</span>';
			                } else {
			                    return '<span class="badge badge-primary">是</span>';
			                }
						}
		            }
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.studentNumber + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.studentNumber + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        }
        
        function queryClassesTreeDaTa()
		{
			// 树结构初始化加载
			var setting = {view:{selectedMulti:false},data:{key:{title:"title"},simpleData:{enable:true}},
				callback:{onClick:function(event, treeId, treeNode){
					tree.expandNode(treeNode);
					if(treeNode.level == "1"){
						$("#gradeNumber").val(treeNode.id);
						$("#classNumber").val("");
					}else if(treeNode.level == "2"){
						$("#gradeNumber").val("");
						$("#classNumber").val(treeNode.id);
					}					
					$.table.search($('form').attr('id'));
				}}
			}, tree, loadTree = function(){
				$.get(ctx + "module/classes/treeData", function(data) {
				    tree = $.fn.zTree.init($("#tree"), setting, data); //.expandAll(true);
				    // 展开第一级节点
				    var nodes = tree.getNodesByParam("level", 0);
				    for (var i = 0; i < nodes.length; i++) {
				        tree.expandNode(nodes[i], true, false, false);
				    }
				    // 展开第二级节点
				    nodes = tree.getNodesByParam("level", 1);
				    for (var i = 0; i < nodes.length; i++) {
				        tree.expandNode(nodes[i], true, false, false);
				    }
				}, null, null, "正在加载，请稍后...");
			};loadTree();
			
			$('#btnExpand').click(function() {
				tree.expandAll(true);
			    $(this).hide();
			    $('#btnCollapse').show();
			});
			$('#btnCollapse').click(function() {
				tree.expandAll(false);
			    $(this).hide();
			    $('#btnExpand').show();
			});
			$('#btnRefresh').click(function() {
			    loadTree();
			});
		}
        
        function getAppellation(id){
        	var s = "";
        	switch (id){
        		case "1":
        			s = "父亲";
        			break;
        		case "2":
        			s = "母亲";
        			break;
        		case "3":
        			s = "爷爷";
        			break;
        		case "9":
        			s = "家长";
        			break;
        		default:
        			s = id;
        	}
        	return s;
        }
    </script>
</body>
</html>